home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: sscanf problems
- Date: 23 Jan 1996 22:50 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <23JAN199622501430@erich.triumf.ca>
- References: <4e4c2v$j2g@mathserv.mps.ohio-state.edu> <4e4h0j$af7@fountain.mindlink.net>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4e4h0j$af7@fountain.mindlink.net>, genew@mindlink.bc.ca (Gene Wirchenko) writes...
- >Chris Mongold <cmongold@magnus.acs.ohio-state.edu> wrote:
- >
- >>Hello,
- >> I'm sorry if this is an inappropriate topic, but I've tried
- >>everything else. I can't seem to get sscanf to to separate a string
- >>into various variable types. Here is an example:
-
- >>#include <stdio.h>
-
- ...
- >>char input[20], crap[17], segment[6], seg_len[3], begin[3], load[3];
- >>int type;
- >>FILE *fp;
- >
- >>printf("File: ");
- >>gets(input);
- >
- > Buffer can be overflowed. You might want to use fgets().
-
- You _do_ want to use fgets() - gets() is evil!
-
- .. snip, snip....
-
- >>fgets(crap, 17, fp);
- >>sscanf(crap, "%d%3s%6s%3s%3s", type, begin, segment, seg_len, load);
- ^^^ This must be &type - you must give scanf()
- the _address_ of (or pointer to) the location it is to store input. The name
- of a char array acts as a pointer to the first location of the array, but you
- must use the "&" operator on ints and similar things.
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-
-
-
-
-